package com.xymtop.api.controller;

import com.xymtop.api.config.ServerStatus;
import com.xymtop.api.entity.Comment;
import com.xymtop.api.service.MyCommentService;
import com.xymtop.api.utils.JsonResoult;
import com.xymtop.api.utils.Timer;
import com.xymtop.api.vo.CommentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName : MyCommentController
 * @Description : 评论的控制器类
 * @Author : 肖叶茂
 * @Date: 2022/12/1  15:41
 */

@RestController
@RequestMapping("comment")
public class MyCommentController {
    @Autowired
    private MyCommentService myCommentService;

    @RequestMapping("/add")
    public JsonResoult<String> addComment(@RequestParam("projectid") String projectid,@RequestParam("userid") String userid,
                                          @RequestParam("type") String type,@RequestParam("content") String content){
        Comment comment = new Comment();
        comment.setId(Timer.getTimeStamp().toString());
        comment.setProjectid(projectid);
        comment.setUserid(userid);
        comment.setType(type);
        comment.setContent(content);

        if(myCommentService.addComment(comment)){
            return new JsonResoult<>(ServerStatus.SUCCESS);
        }else {
            return new JsonResoult<>(ServerStatus.Fail);
        }

    }

    @RequestMapping("delete")
    public JsonResoult<String> deleteComment(@RequestParam("id") String id){
        if(myCommentService.deleteComment(id)){
            return new JsonResoult<>(ServerStatus.SUCCESS);
        }else {
            return new JsonResoult<>(ServerStatus.Fail);
        }
    }

    @RequestMapping("getComment")
    public  JsonResoult<Comment> getComment(@RequestParam("id") String id){
        return new JsonResoult<Comment>(200,"", myCommentService.getComment(id));
    }

    @RequestMapping("getCommentByProjectId")
    public  List<Comment> getCommentByProjectId(@RequestParam("projectid") String projectid) {
        return myCommentService.getCommentByProjectId(projectid);
    }

    @RequestMapping("getComments")
    public  List<CommentVO> getComments(@RequestParam("projectid") String projectid){
        return myCommentService.getComments(projectid);
    }

}
